//文件解包工具
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1000
struct Jiebao{
    char filename[200];
    long filesize;
};

int main(int argc,const char * argv[]) {
    long num;
    int i;
    int j;
    char c;
    FILE*fp=fopen(argv[1],"rb");
    if(fp==NULL)
        return -1;
    //从打包后的文件中读取文件的个数
    fread(&num,1,sizeof(num),fp);
    printf("%ld\n",num);
    struct Jiebao*p=(struct Jiebao*)malloc(sizeof(struct Jiebao)*num);
    //从打包后的文件中读取文件信息
    fread(p,1,sizeof(struct Jiebao)*num,fp);
    //创建新文件  从打包后的文件中读取文件内容到新文件
    FILE*fp2;
    for(i=0;i<num;i++){
        fp2=fopen(p[i].filename,"wb");
        if(fp2==NULL)
            return -1;
        for(j=0;j<p[i].filesize;j++){
            fread(&c,1,1,fp);
            fwrite(&c,1,1,fp2);
        }
        fclose(fp2);
    }
    fclose(fp);
    printf("文件解包完毕\n");
    return 0;
}
